package com.example.shopping.parsers;

import com.example.shopping.api.SHResponseData;
import com.example.shopping.shdatas.SHError;
import com.example.shopping.shdatas.SHSuccessMessage;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by doanht on 12/5/13.
 */
public class SHUpdateProduceParserData extends SHBaseParserData {
    public String requiredResponseType() {
        return "SaveParser";
    }

    public SHResponseData parseData(JSONObject response) throws org.json.JSONException {
        if (response == null) return null;

        SHError error = null;
        try {
            error = (SHError) this.errorParserData.parseData(response);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if (error != null && error.statusCode > 0) {
            return error;
        }

        SHSuccessMessage produce = new SHSuccessMessage();
        JSONObject jsonItem = response.getJSONObject("success");
        if (jsonItem != null) {
            produce.message = jsonItem.getString("message");
        }


        return produce;
    }
}
